#!/bin/env python3


import os
import requests
import sys

def get_pr():
    f = open("/root/pkglist14", "r")
    msg = f.readlines()
    token = "d0c300b0001c27a93cf4d31e24b56ad2"
    for p in msg:
        pkg = p.strip()
        api_url = "https://gitee.com/api/v5/repos/src-openeuler/%s/pulls?access_token=%s&state=merged&sort=created&direction=desc&page=1&per_page=100" % (pkg, token)
        rep = requests.request(method='get', url = api_url)
        res = rep.json()
        for tmp in res:
            try:
                pr_url = tmp['html_url']
                owner = tmp['head']['user']['name']
                branch = tmp['base']['label']
                time = tmp['merged_at'].split("T")[0]
            except:
                print("ERROR:%s" % pkg)
            cmd = "echo \"%s %s %s %s %s\" >> pr_log "% (pkg, pr_url, owner, branch, time)
            ret = os.system(cmd)

get_pr()

